export default {
    namespaced: true,
    state: {
        list: [
            { id: 100, name: "吃饭", isDone: true },
            { id: 101, name: "睡觉", isDone: false },
            { id: 102, name: "打豆豆", isDone: true },
              ]
    },
    mutations: {
        setList(state,status) {
            state.list[status].isDone = !state.list[status].isDone
        },
        delList(state, index) {
            state.list.splice(index,1)
        },
        addList(state, value) {
            const id = state.list.length === 0 ? 100 : state.list.at(-1).id+1
            const newTask = { id: id, name: value, isDone: false }
            state.list.push(newTask)
        },
        changIsAll(state, val) {
            state.list.forEach(item => item.isDone = val)   
        },
        clearIsDone(state) {
           state.list =  state.list.filter(item => !item.isDone)
        }
    }
}